﻿// ////////////////////////////////////////////////////////////////////////////
// 
// SWE Case Tool
// 
// Solution:	CaseTool
// Project:		4. MethodCocomo
// Filename:	ChangedPanel.cs
// 
// File Created:	18:42 31.05.2013 
// Last Changed:	18:11 05.06.2013
// 
// ////////////////////////////////////////////////////////////////////////////

using System;
using System.Windows.Forms;

namespace SWE.CaseTool.Methods.Controls
{
	/// <summary>
	/// Panel which inherits from the IChanged interface. If possible every change event is directly forwarded to the panel's parent
	/// </summary>
	internal class ChangedPanel : Panel, IChanged
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="ChangedPanel"/> class.
		/// </summary>
		public ChangedPanel()
		{
			Changed += (sender, args) =>
				{
					if (Parent is IChanged && ((IChanged) Parent).Changed != null)
					{
						((IChanged) Parent).Changed(this, EventArgs.Empty);
					}
				};
		}

		/// <summary>
		/// Gets or sets the changed event handler for notifiing the parent of changes in it's child objects.
		/// E.G. a change in a
		/// subcontrol which modifies a parameter, a recalcutation of the whole project is needed. The child
		/// control then uses the Changed-Method of it's parent to tell him that something has changed
		/// </summary>
		/// <value>
		/// The changed event handler.
		/// </value>
		public ChangedEventHandler Changed { get; set; }
	}
}